<template>
	<view>
		<view class="merchant-msg">
			<image :src="`${$imgurl}/static/head.png`" />
			<view class="name">
				好谜holymily
			</view>
		</view>
		<view class="wechat_login">
			<view class="btn-wrapper">
				
				<!-- <button class="bg-theme btn1" open-type="getPhoneNumber" -->
					<!-- @getphonenumber="getphonenumber">授权登录</button> -->
				<button class="bg-theme btn1" @click="getAuthLogin">
					授权登录
				</button>
				<!-- <button v-if="configData.phone_auth_switch" hover-class="none" @click="phoneLogin"
					class="btn2">{{$t(`手机号登录`)}}</button> -->
			</view>
		</view>
	</view>
</template>

<script setup>
	
	import {authLogin,authType} from "/api/user"
	import {onLoad} from "@dcloudio/uni-app"
	import {useStore} from "vuex"
	const store=useStore()
	let code=''
	onLoad(()=>{
		
		
	})
	const getAuthLogin=()=>{
		wx.login({
			success:async (res)=>{
				code=res.code
				let auth_type = await authType({params:{code:res.code}})
				let loginRes = await authLogin({params:{key:auth_type.data.key}})
				store.commit('user/setToken',loginRes.data.token)
				store.dispatch('user/setUserInfo')
				uni.navigateBack()
				// console.log(loginRes)
			}
		})
	}
	const getPhoneNumber=async (e)=>{
		if(e.detail.code){
			let re = await getToken({
				code: code,
				encryptedData:e.detail.encryptedData,
				iv:e.detail.iv
			})
			store.commit('user/setToken',re.token)
			store.commit('user/setUserInfo',re)
			uni.navigateBack()
		}
	}
</script>

<style lang="scss">
	.merchant-msg {
		padding-top: 252rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
		z-index: 2;
		image {
			width: 152rpx;
			height: 152rpx;
			border-radius: 50%;
		}
	
		.name {
			font-size: 40rpx;
			font-weight: 500;
			color: #333333;
			line-height: 56rpx;
			margin-top: 32rpx;
		}
	}
	
	.wechat_login {
		margin-top: 96rpx;
	
		.img image {
			width: 100%;
		}
	
		.btn-wrapper {
			padding: 0 66rpx;
	
			button {
				width: 100%;
				height: 86rpx;
				line-height: 86rpx;
				margin-bottom: 40rpx;
				border-radius: 120rpx;
				font-size: 30rpx;
				background: linear-gradient( 125deg, #FF9940 0%, #FD2A00 100%);
				color: #fff;
				&.btn1 {
					color: #fff;
				}
	
				&.btn2 {
					color: #666666;
					border: 1px solid #E4E4E4;
				}
			}
		}
	}
</style>
